package com.cgt.day6;

import org.junit.Test;

import java.util.Scanner;

public class Homework {
    @Test
    public void test1(){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        System.out.println(str);
//        System.out.println(trim1(str));
        System.out.println(trim2(str));
    }

    public String trim1(String str){
        if(str.equals("") || (str == null))  return  "";

        int beginindex = 0;
        int endindex =str.length()-1;

        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) != '-') {
                beginindex = i;
                break;
            }
        }

        for (int j = str.length()-1; j > beginindex; j--) {
            if(str.charAt(j) != '-'){
                endindex = j;
                break;
            }
        }
        return str.substring(beginindex, endindex + 1);
    }

    public String trim2(String str){
        if(str.equals("") || (str == null))  return  "";
        int beginindex = 0;
        int endindex =str.length()-1;

        while(str.charAt(beginindex) == '-'){
            beginindex++;
        }
        while((str.charAt(endindex) == '-') && (endindex > beginindex)){
            endindex--;
        }
        return str.substring(beginindex, endindex + 1);
    }

    @Test
    public void test2(){
        String str1 = "I Love Java！";
        String str2 = str1.replace("I","i").replace("L","l").replace("J","j");
        System.out.println(str2);
    }
}
